package com.example.kingdee.sqlTool.singleton;

import com.kingdee.bos.webapi.entity.IdentifyInfo;
import com.kingdee.bos.webapi.sdk.K3CloudApi;

import java.io.*;
import java.util.Properties;

public class Singleton {

    private static volatile K3CloudApi k3CloudApi;

    public static K3CloudApi getInstance() throws IOException {
        if (k3CloudApi == null) {
            synchronized (K3CloudApi.class) {
                if (k3CloudApi == null) {
                    Properties properties = new Properties();
                    String path = System.getProperty("user.dir") + "\\files\\kdwebapi.properties";
                    File file = new File(path);
                    System.out.println("读取根目录下的配置文件->" + file.getPath());
                    InputStream inputStream = new FileInputStream(file.getPath());
                    properties.load(new InputStreamReader(inputStream, "utf-8"));
                    inputStream.close();
                    IdentifyInfo iden = new IdentifyInfo();
                    iden.setUserName(properties.getProperty("X-KDApi-UserName"));
                    iden.setAppId(properties.getProperty("X-KDApi-AppID"));
                    iden.setdCID(properties.getProperty("X-KDApi-AcctID"));
                    iden.setAppSecret(properties.getProperty("X-KDApi-AppSec"));
                    iden.setlCID(2052);
                    iden.setServerUrl(properties.getProperty("X-KDApi-ServerUrl"));
                    k3CloudApi = new K3CloudApi(iden);
                }
            }
        }
        return k3CloudApi;
    }
}
